package com.sinooceangroup.capital.gateway;

import com.sinooceangroup.capital.gateway.filter.NormalGatewayFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

/**
 * Gateway Demo
 * @author: Leo.Wang, adwyxx@qq.com
 * @date: 2020/7/17 14:56
 */
@EnableDiscoveryClient
@SpringBootApplication
public class GatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class,args);
    }

    /***
     * 自定GatewayFilter应用，代码中配置
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes().route(r ->
                r.path("/consumer/filter/**")
                        .uri("lb://consumer-service:8080")
                        .filters(new NormalGatewayFilter())
                        .id("consumer-service-route-1"))
                .build();
    }
}
